<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改审读稿件')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-review-edit" th:object="${rvReview}">
            <input name="id" th:field="*{id}" type="hidden">

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">关联样本：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input type="text" id="sampleid" name="sampleid"  th:field="*{sampleid}"
                                       class="form-control" placeholder="" readonly required>
                                <span class="input-group-btn">
                            <button type="button" class="btn btn-primary" onclick="selectSample()">关联样本
                            </button>
                            </span>
                            </div>
                            <span class="help-block m-b-none">点击关联按钮</span>
                        </div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <input type="text" readonly id="names" class="form-control" th:value="${status}" placeholder="" >
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">审读介质：</label>
                        <div id="element" class="col-sm-8 ">
                            <div class="form-row">
                                <div class="form-group col-sm-6">
                                    <select name="mediumSuper"  th:attr="data-value=*{mediumSuper}" class="type form-control " data-first-title="请选择"
                                            required>
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                                <div class=" form-group col-sm-6">
                                    <select name="mediumSub"  th:attr="data-value=*{mediumSub}" class="router form-control " data-first-title="请选择"
                                            required>
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">审读专家：</label>
                        <div class="col-sm-8">
                            <div class="form-row">
                                <div class=" form-group col-sm-5 ">
                                    <input type="text" name="expertId"  th:field="*{expertId}" class="form-control" placeholder="" readonly
                                           required>
                                    <span class="help-block m-b-none">点击选择按钮</span>
                                </div>
                                <div class=" form-group col-sm-1 ">
                                    <span>-</span>
                                </div>
                                <div class="form-group col-sm-6 ">
                                    <div class="input-group">
                                        <input type="text" name="expertName"  th:field="*{expertName}" readonly class="form-control" placeholder=""
                                               required>
                                        <span class="input-group-btn">
                                    <button type="button" class="btn btn-primary" onclick="selectExpert()">选择
                                    </button>
                                    </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">提交时间：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="submitDate" th:value="${#dates.format(rvReview.submitDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">题材内容：</label>
                        <div class="col-sm-8">
                            <select name="subjectContent" class="form-control m-b" th:with="type=${@dict.getType('manuscript_theme')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{subjectContent}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">稿件形式：</label>
                        <div class="col-sm-8">
                            <select name="form" class="form-control m-b" th:with="type=${@dict.getType('manuscript_form')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{form}"></option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">稿件倾向：</label>
                        <div class="col-sm-8">
                            <select name="inclination" class="form-control m-b" th:with="type=${@dict.getType('manuscript_tropesis')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{inclination}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">稿件费用：</label>
                        <div class="col-sm-8">
                            <div class="input-group m-b">
                                <span class="input-group-addon">¥</span>
                                <input type="number" name="cost" th:field="*{cost}" class="form-control" required >
                                <span class="input-group-addon">元</span>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-6">
                    <!-- form-group  -->
                    <div class="row">
                        <label class="col-sm-4 control-label is-required">采用情况：</label>
                        <div class="col-sm-3">
                            <select name="adoption" class="form-control m-b" th:with="type=${@dict.getType('manuscript_use')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{adoption}"></option>
                            </select>
                        </div>
                        <label class="col-sm-2 control-label ">期刊/说明：</label>
                        <div class="col-sm-3">
                            <input name="journalDesc" th:field="*{journalDesc}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label ">备注：</label>
                        <div class="col-sm-8">
                            <input name="remark" th:field="*{remark}" class="form-control" type="text">
                        </div>
                    </div>
                </div>

                <div class="col-md-6">
                    <!-- form-group  -->
                    <div class="row">
                        <label class="col-sm-4 control-label is-required">稿件来源：</label>
                        <div class="col-sm-3">
                            <select name="source" class="form-control m-b" th:with="type=${@dict.getType('manuscript_source')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{source}"></option>
                            </select>
                        </div>
                        <label class="col-sm-2 control-label ">说明：</label>
                        <div class="col-sm-3">
                            <input name="reviewDesc" th:field="*{reviewDesc}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">稿件名称：</label>
                        <div class="col-sm-4">
                            <input name="reviewName" th:field="*{reviewName}" class="form-control" type="text" required>

                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">稿件内容：</label>
                        <div class="col-sm-10">
                            <textarea name="reviewContent" th:field="*{reviewContent}"  class="form-control" placeholder="输入稿件内容"
                                      rows="10"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">其它说明：</label>
                        <div class="col-sm-10">
                            <textarea name="otherDesc" th:field="*{otherDesc}" maxlength="500" class="form-control" placeholder="输入其它说明"
                                      rows="3"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label">附件：</label>
                    <div class="col-sm-10">
                        <input name="append" th:field="*{append}"  type="hidden" readonly>
                        <br/>
                        <div class="file-loading">
                            <input class="form-control file-upload" multiple id="append" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>


            <div class="row">
                <div class="col-sm-offset-5 col-sm-10">
                    <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i
                            class="fa fa-check"></i>保 存
                    </button>&nbsp;
                    <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i
                            class="fa fa-reply-all"></i>关 闭
                    </button>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <th:block th:include="include :: jquery-cxselect-js"/>
    <th:block th:include="include :: select2-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "publish/review";
        $("#form-review-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", $('#form-review-edit').serialize());
            }
        }

        $("input[name='submitDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        var sca = function (event) {
            $("input[name='" + event.currentTarget.id + "']").val("");
            sca = function () {
            }
        }

        $(".file-upload").each(function (i) {
            var vals = new Array()
            var preList = new Array();
            if ($.common.isNotEmpty($("input[name='" + this.id + "']").val())) {
                var str = $("input[name='" + this.id + "']").val();
                var strs = new Array();
                strs = str.split(",");
                for (i = 0; i < strs.length; i++) {
                    vals[i] = ctx.slice(0, ctx.length - 1) + strs[i];
                }
            }
            var previewJson = preList;
            var preConfigList = new Array();
            for ( var i = 0; i < vals.length; i++) {
                var array_element = vals[i];
                var name=vals[i].substring(vals[i].lastIndexOf("/")+1);
                var tjson = {
                    caption: name, // 展示的文件名
                    width: '100px',
                    alt:array_element,
                    extra: {id: 100}
                };
                preConfigList[i] = tjson;
            }

            $(this).fileinput({
                uploadUrl: '/common/upload',
                initialPreviewAsData: true,
                initialPreview: vals,
                maxFileCount: 0,
                showUpload: false,
                overwriteInitial:false, //设置重新上传文件不顶替原有文件
                showRemove: true,
                maxFileSize: 30000,
                autoReplace: true,
                //allowedFileExtensions: ['jpg', 'png', 'bmp', 'jpeg'],
                showUpload: false, //是否显示上传按钮
                showCaption: true,//是否显示标题
                browseClass: "btn btn-primary",//按钮样式
                dropZoneTitle: "拖拽文件到这里",
                previewFileIcon: '<i class="fa fa-file-o text-info"></i>',
                otherActionButtons:'<button type="button" class="kv-file-down btn btn-sm btn-default" {dataKey} title="下载附件"><i class="fa fa-cloud-download"></i></button>',
                layoutTemplates: {
                    //     actionDelete: '', //去除上传预览的缩略图中的删除图标
                    //     actionUpload: '',//去除上传预览缩略图中的上传图片图标；
                    //actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
                },
                initialPreviewConfig: preConfigList,
                preferIconicPreview: true,// 是否优先显示图标  false 即优先显示图片
                previewFileIconSettings: {
                    'docx': '<i class="fa fa-file-word-o text-primary"></i>',
                    'doc': '<i class="fa fa-file-word-o text-primary"></i>',
                    'xlsx': '<i class="fa fa-file-excel-o text-success"></i>',
                    'xls': '<i class="fa fa-file-excel-o text-success"></i>',
                    'pptx': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                    'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                    'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
                    'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
                    'sql': '<i class="fa fa-file-word-o text-primary"></i>',
                    'txt': '<i class="fa fa-file-text-o text-info"></i>',
                    'rtf': '<i class="fa fa-file-text-o text-info"></i>',
                },
            }).on('filebatchselected', function (event, data, id, index) {
                $(this).fileinput("upload");
            }).on('fileuploaded', function (event, data, previewId, index) {
                //若重新上传文件，清空当前文件路径,只执行一次清空函数
                //sca(event);
                if ($("input[name='" + event.currentTarget.id + "']").val()== null || $("input[name='" + event.currentTarget.id + "']").val() == "") {
                    $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName);
                } else {
                    $("input[name='" + event.currentTarget.id + "']").val($("input[name='" + event.currentTarget.id + "']").val() + ',' + data.response.fileName);
                }
            }).on('filecleared', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            }).on('filesuccessremove', function (event, id, index) {//删除新上传的文件
                var nu=-1;
                var src = $("#"+id).attr("title");
                var fileUrlList = $("input[name='" + event.currentTarget.id + "']").val().split(",");
                if(src==""||src==null){
                    src = $("#"+id+" img").attr("title");
                    for(var i = 0 ;i<=fileUrlList.length-1;i++){
                        var src1 = fileUrlList[i].substring(fileUrlList[i].lastIndexOf("/")+1);
                        if(src1 == src ){
                            nu =i;
                        }
                    }
                }else{
                    for(var i = 0 ;i<=fileUrlList.length-1;i++){
                        var title1 = fileUrlList[i].substring(fileUrlList[i].lastIndexOf("/")+1);
                        if(title1 == src ){
                            nu =i;
                        }
                    }
                }
                fileUrlList.splice(nu, 1);
                $("input[name='" + event.currentTarget.id + "']").val(fileUrlList);
            }).on('filedeleted', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            }).on('filepreremove', function (event, id, index) {//删除已加载有的文件
                var nu=-1;
                var src = $("#"+id).attr("title");
                var fileUrlList = $("input[name='" + event.currentTarget.id + "']").val().split(",");
                if(src==""||src==null){
                    src = $("#"+id+" img").attr("src");
                    for(var i = 0 ;i<=fileUrlList.length-1;i++){
                        var src1 = fileUrlList[i];
                        if(src1 == src ){
                            nu =i;
                        }
                    }
                }else{
                    for(var i = 0 ;i<=fileUrlList.length-1;i++){
                        var title1 = fileUrlList[i].substring(fileUrlList[i].lastIndexOf("/")+1);
                        if(title1 == src ){
                            nu =i;
                        }
                    }
                }
                fileUrlList.splice(nu, 1);
                $("input[name='" + event.currentTarget.id + "']").val(fileUrlList);
            });
            $(this).fileinput('_initFileActions');
        });


        /**
         * 其他按钮（如下载）绑定时间
         */
        $(document).on('click', '.kv-file-down', function (e, id, index) {
            var download = "";
            // 获取父级DIV
            debugger
            var fileIndex = $(this).parents(".file-preview-frame").attr("data-fileindex");
            var fileValue = $(this).parents(".col-sm-10").children("input").val();
            if(!isNaN(fileIndex)){
                var title = $(this).parents(".file-preview-frame").attr("title");
                var id = $(this).parents(".file-preview-frame").attr("id");
                if(title==""||title==null){
                    title = $("#"+id+" img").attr("title");
                    for(var i = 0 ;i<=fileValue.split(",").length-1;i++){
                        var title1 = fileValue.split(",")[i].substring(fileValue.split(",")[i].lastIndexOf("/")+1);
                        if(title1 == title ){
                            download =fileValue.split(",")[i];
                        }
                    }
                }else{
                    for(var i = 0 ;i<=fileValue.split(",").length-1;i++){
                        var title1 = fileValue.split(",")[i].substring(fileValue.split(",")[i].lastIndexOf("/")+1);
                        if(title1 == title ){
                            download =fileValue.split(",")[i];
                        }
                    }
                }
            }else {
                var number = fileIndex.match(/\d/);
                if (number) {
                    download = fileValue.split(",")[number];
                }
            }
            var name=download.substring(download.lastIndexOf("/")+1);
            if(download!=""){
                downloadFile(download,name);
            }
        })

        function downloadFile(url,name){
            var a = document.createElement("a");
            a.download = name;
            a.href = url;
            $("body").append(a); // 修复firefox中无法触发click
            a.click();
            $(a).remove();
        }

        var mediumdata = [
            {   //新闻报、行业报、区县报、大学报
                "s": [
                    {"s": null, "v": "新闻报", "n": "新闻报"},
                    {"s": null, "v": "行业报", "n": "行业报"},
                    {"s": null, "v": "区县报", "n": "区县报"},
                    {"s": null, "v": "大学报", "n": "大学报"},
                ],
                "v": "报纸",
                "n": "报纸"
            },
            {   //公开刊物、连续性内部资料、大学学报
                "s": [
                    {"s": null, "v": "公开刊物", "n": "公开刊物"},
                    {"s": null, "v": "连续性内部资料", "n": "连续性内部资料"},
                    {"s": null, "v": "大学学报", "n": "大学学报"},
                ],
                "v": "期刊",
                "n": "期刊"
            },
            {   //公开发行图书、非连续性内部资料
                "s": [
                    {"s": null, "v": "公开发行图书", "n": "公开发行图书"},
                    {"s": null, "v": "非连续性内部资料", "n": "非连续性内部资料"},
                ],
                "v": "图书",
                "n": "图书"
            },
            {   // 资讯、小说、游戏
                "s": [
                    {"s": null, "v": "资讯", "n": "资讯"},
                    {"s": null, "v": "小说", "n": "小说"},
                    {"s": null, "v": "游戏", "n": "游戏"},
                ],
                "v": "互联网出版",
                "n": "互联网出版"
            },
            {   //渝版、非渝版
                "s": [
                    {"s": null, "v": "渝版", "n": "渝版"},
                    {"s": null, "v": "非渝版", "n": "非渝版"},
                ],
                "v": "发行",
                "n": "发行"
            },
            {   //半月刊、月刊、双月刊、季刊
                "s": [
                    {"s": null, "v": "电子", "n": "电子"},
                    {"s": null, "v": "音像", "n": "音像"},
                ],
                "v": "电子音像",
                "n": "电子音像"
            }
        ];
        $('#element').cxSelect({
            selects: ['type', 'router'],
            jsonValue: 'v',
            data: mediumdata
        });

        function selectExpert() {
            $.modal.open("选择专家", ctx + "publish/managementt/expertSelect");
        }
        function selectSample() {
            $.modal.open("关联样本", ctx + "publish/sample/sampleSelect",1200);
        }
        // 设置专家
        function setExpert(ids, names) {
            // debugger
            $("input[name='expertId']").val(ids);
            $("input[name='expertName']").val(names);
        }

        // 设置样本
        function setSample(rows){
            var _ids=[];
            var _names=[];
            rows.forEach(function(item){
                _ids.push(item.id);
                _names.push(item.name);
            })
            $('#sampleid').val(_ids.join(','));
            $('#names').val(_names.join(','));
        }
    </script>
</body>
</html>